﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using zeus.Core;
using zeus.Core.RepositoryInterfaces;
using SharpArch.Data.NHibernate;
using SharpArch.Core.PersistenceSupport;
using NHibernate;
using NHibernate.Transform;
using NHibernate.Criterion;
using SharpArch.Core;

namespace zeus.Data.NHibernateMaps
{
    public class MenuRepository : Repository<Menu>, IMenuRepository
    {
        /// <summary>
        /// Recuperar las opciones del menu
        /// </summary>
        /// <param name="rol"></param>
        /// <returns></returns>
        public IList<Menu> GetByRol(string rol)
        {
            int codigoRol = 0;

            switch (rol)
            {
                case "admin":
                    codigoRol = 1;
                    break;
                case "cliente":
                    codigoRol = 2;
                    break;
                default:
                    codigoRol = 3;
                    break;
            }

            return Session.CreateSQLQuery("select * from menu inner join menu_rol on menu.men_id = menu_rol.men_id where rol_id = :rol_id")
                    .AddEntity(typeof(Menu))
                    .SetInt32("rol_id", codigoRol)
                    .List<Menu>();
        }
    }
}
